/*
 * utils.c
 *
 *  Created on: 3 nov. 2012
 *      Author: Rania ToumiGasri
 */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string.h>
#include "utils.h"

///////////////////////////////////////////////////////
int existingCenter(int* tab, int nb, int position) {
	int i;
	for (i = 0; i < position; i++) {
		if (tab[i] == nb) {
			return 1;
		}
	}
	return 0;
}
/////////////////////////////////////////////////////
void printData(Data* mydata) {
	int i, j;
	printf("****************\nla liste des points : \n");
	for (i = 0; i < mydata->nombreDesDonnees; i++) {
		printf("(");
		for (j = 0; j < mydata->dimensionDesDonnees; j++) {
			printf("%f,", mydata->data[i][j]);
		}
		printf("%f)\n", mydata->data[i][mydata->dimensionDesDonnees]);
	}
	printf("\n****************\n");
}

///////////////////////////////////////////////////
void printCenters(Map* mycenters) {
	int i, j;
	printf("****************\nla liste des centre : \n");
	for (i = 0; i < mycenters->nombreDeCentre; i++) {
		printf("(");
		for (j = 0; j < mycenters->dimensionDesDonnees; j++) {
			printf("%.7le,", mycenters->codeBook[i][j]);
		}
		printf("%.7le)\n", mycenters->codeBook[i][j]);
	}
	printf("\n****************\n");
}
/////////////////////////////////////////////////////
void printCentersToFile(Map* centres, FILE * output) {
	int i, j;
	for (i = 0; i < centres->nombreDeCentre; i++) {
		for (j = 0; j < centres->dimensionDesDonnees; j++) {
			fprintf(output, "%f\t", centres->codeBook[i][j]);
		}
		fprintf(output, "\n");
	}
}
/////////////////////////////////////////////////////

void printPoint(double* coord, int dataDimention) {
	int i;
	printf("point(");
	for (i = 0; i < dataDimention; i++) {
		printf("%f,", coord[i]);
	}
	printf("%f)\n", coord[dataDimention]);
}
